package com.renwei.yunlong.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.renwei.yunlong.R;
import com.renwei.yunlong.adapter.TablayoutAdapter;
import com.renwei.yunlong.base.BaseLazyFragment;
import com.renwei.yunlong.view.SimpleOptionView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wangqi on 2018/4/16.
 */

public class KnowInformationFragment extends BaseLazyFragment {

    @Bind(R.id.tab_layout)
    TabLayout tabLayout;
    @Bind(R.id.v_pager)
    ViewPager vPager;
    @Bind(R.id.simpleTileView)
    SimpleOptionView simpleTileView;

    private String knowledgeId;

    public KnowInformationFragment(String knowledgeId) {
        this.knowledgeId = knowledgeId;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_know_infomation;
    }

    @Override
    public void onLazyLoad() {
        initView();
    }

    private void initView() {
        simpleTileView.setTitle("知识详情");

        List<Fragment> list = new ArrayList<>();
        list.add(new KnowDetailsFragment(knowledgeId));
        list.add(new BaseAnnexFragment(knowledgeId,"know"));
        list.add(new BaseHistoryFragment(knowledgeId,"know","0"));
        list.add(new KnowRelatedFragment(knowledgeId));

        String[] titles = {"详情", "附件", "历史", "相关"};
        //ViewPager的适配器
        TablayoutAdapter adapter = new TablayoutAdapter(getChildFragmentManager(), list, titles);
        vPager.setAdapter(adapter);
        vPager.setOffscreenPageLimit(4);
        //绑定
        tabLayout.setupWithViewPager(vPager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        getActivity().finish();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
